Experiments

In [1]:
# Imports
import math as m
import numpy as np
import matplotlib.pyplot as plt
import holoviews as hv
import pylab as pl
from pylab import exp,cos,sin,pi,tan, pi
import pandas as pd
import seaborn as sb
import holoviews as hv
from IPython.display import SVG
import io
from PIL import Image
from random import random
import elastica as el
import elastica_neurons as en
from dynamics import *
%matplotlib inline
hv.notebook_extension()
/afs/inf.ed.ac.uk/user/s12/s1247380/Documents/HonoursProject/Python/venv/lib/python2.7/site-packages/IPython/html.py:14: ShimWarning: The `IPython.html` package has been deprecated. You should import from `notebook` instead. `IPython.html.widgets` has moved to `ipywidgets`.
  "`IPython.html.widgets` has moved to `ipywidgets`.", ShimWarning)
HoloViewsJS successfully loaded in this cell.

Example inputs

In [68]:
m = 11
n = 11
np.random.seed(42)
ac_orient1 = np.pi*np.random.rand(m,n)
ac_orient1[2:8,5] = 0
visualField(ac_orient1)
Out[68]:
In [38]:
ac_orient2 = np.pi/2*np.ones((m,n))
ac_orient2[5,5] = 0
visualField(ac_orient2)
Out[38]:
In [49]:
ac_orient3 = np.pi/2*np.ones((m,n))
for i in range(m):
    ac_orient3[i,i] = 3*np.pi/4
visualField(ac_orient3)
Out[49]:
In [112]:
np.random.seed(67)
ac_orient4 = np.pi*np.random.rand(m,n)
ac_orient4[2:8,6] = np.random.rand(6)/5


visualField(ac_orient4)
Out[112]:
In [122]:
m = 5
n = 2
dimensions = ['X', 'Y']
ac_orient = np.reshape(np.pi*np.arange(m*n)/(m*n), (m,n))
keys = [(i,j) for i in range(m) for j in range(n)]
vf_holomap = hv.HoloMap([(k, visualField(ac_orient[k])) for k in keys], kdims=dimensions)
vf_holomap
Out[122]:
In [114]:
a = np.ones(3)
b = np.arange(0,1.5,0.5)
curve1 = hv.Curve(zip(a,b))
curve2 = hv.Curve(zip(b,a))
curve1*curve2(style={'visible':False})
a = np.ones(5)
b = np.arange(0,0.5,0.1)
curve2 = hv.Curve(zip(b,a))
#b*curve2
In [123]:
a = np.ones(3)
b = np.arange(0,1.5,0.5)
curve1 = hv.Curve(zip(np.tile(1, 3),b))
curve2 = hv.Curve(zip(b,np.tile(1, 3)))
a = np.ones(5)/2
b = np.arange(0.3,0.8,0.1)
curve1*curve2(style={'visible':False})*hv.Curve(zip(b,a))
Out[123]:
In [124]:
%output size=100
plotbar(1,1,1,width=4)
Out[124]:
In [117]:
x = -np.matrix(np.arange(12).reshape((3,4))); x
type(x)
Out[117]:
numpy.matrixlib.defmatrix.matrix
In [6]:
%output size=400
#ac_orient = np.array([[0],[np.pi/4],[np.pi/2],[3*np.pi/4]])
ac_orient = np.array([[-0.1],[0.2]])
mag = np.array([[1],[1]])
a = visualField(ac_orient, aspect=2, fix_scale=True)
a
Out[6]:

Generate weight matrices

We define full connectivity matrices. Every orientation selective neuron from part of the visual field is connected to all other orientation selective neurons from other parts of the visual field. Let's say we have a visual field with size 10x10, with 9 orientation selective neurons for each field. In order to have a full connectivity matrix, we define an mxm matrix, where m=10109. In this way we define the stregth of every neuron to every other neuron. We don't have any connections between neurons in the same part of the visual field. Try to do checks either by visualizing or simple sanity checks. For example we can check if we have setup the correct connection to zero. Number of all connection - 810000, from which 10109*9=8100 should not be connect to each other. When we check that's indeed the case.

In [7]:
%%output size=150

m = 1
n = 2
tau = 6
# Number of orientation selective neurons
nosn = 9
timesteps = 100
# for vonMises function
k = 0.25
A = 3
# for the weight matrix
distance_scaling = 0.1
orientation_scaling = 0.1

results, rs, direction, magnitude = runExperiment('my',m,n,nosn,ac_orient,timesteps,tau,k=0.25,A=3)
In [8]:
results
Out[8]:
In [6]:
magnitude[0,0,:]
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-6-cf88bc42ce52> in <module>()
----> 1 magnitude[0,0,:]

NameError: name 'magnitude' is not defined
In [9]:
%%output size=150

t = np.arange(0,timesteps,1)
setNumberOfColors(nosn)
 
plotOneField((0,0),t,nosn,rs)
Out[9]:
In [12]:
plt.plot(direction[0,0,:])
Out[12]:
[<matplotlib.lines.Line2D at 0x1635e510>]
In [9]:
sum(sum(matrix2))
Out[9]:
22.032640390862124
In [3]:
%%output size=300
matrix2 = np.load('weight_matrices/10x10x9my.npy')
plt.figure(figsize=[20, 20])
plt.imshow(matrix2)
plt.colorbar()
In [34]:
a.shape[0]
Out[34]:
900
In [19]:
%%output size=300
a = generateWeightMatrix(type='my', m=1,n=2, nosn=9, distance_factor=0.003, orientation_factor=0.001)
showWeights(a,fig_size=20)
In [3]:
%%output size=300
a = generateWeightMatrix(type='el', m=8,n=8,nosn=9)
showWeights(a,fig_size=30)
In [11]:
%%output size=150
m = 10
n = 10
tau = 6
# Number of orientation selective neurons
nosn = 9
timesteps = 100
# for vonMises function
k = 0.25
A = 3
# for the weight matrix
distance_scaling = 0.00005
orientation_scaling = 0.00005
# Set the number of colors for plotting, based on the number of orientation selective neurons
setNumberOfColors(nosn)

orientations = np.arange(0, np.pi, np.pi/nosn)
#ac_orient = np.random.rand(m,n)
responses = np.zeros((nosn, timesteps))
t = np.arange(0,timesteps,1)

spikes_ = vonMises(A,k,ac_orient,orientations)
spikes = spikes_.ravel()
r = np.zeros(len(spikes))
drdt = spikes/tau
rs = np.zeros(spikes.shape + (len(t),))

for s in range(len(t)):
    r = r + drdt
    drdt = (-r + spikes)/tau + np.dot(matrix,r)
    rs[:,s] = r

#r_first_neuron = rs[:,1,1,:]
rs = np.reshape(rs, spikes_.shape + (len(t),))
#(direction, magnitude) = populationVector(orientations, rs, nosn, timesteps)
#dimensions = ['T']
#keys = [i for i in range(timesteps)]
#oneColor()
#r_first_neuron_hm = [(k, visualFieldMagnitude(direction[:,:,k],magnitude[:,:,k])) for k in keys]
#sections = hv.HoloMap(r_first_neuron_hm, kdims=dimensions)
#sections
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-11-526fca7a6d73> in <module>()
     19 t = np.arange(0,timesteps,1)
     20 
---> 21 spikes_ = vonMises(A,k,ac_orient,orientations)
     22 spikes = spikes_.ravel()
     23 r = np.zeros(len(spikes))

NameError: name 'ac_orient' is not defined
In [11]:
rs.shape
plotOneField((1,0),t,nosn,rs)
Out[11]:
In [14]:
#r_first_neuron = rs[:,1,1,:]
m = 10
n = 10
tau = 6
timesteps = 100
# Number of orientation selective neurons
nosn = 9
orientations = np.arange(0, np.pi, np.pi/nosn)

rs = np.load('weight_matrices/10x10x9my_rs.npy')      
(direction, magnitude) = populationVector(orientations, rs, nosn, timesteps)
dimensions = ['T']
keys = [i for i in range(timesteps)]
oneColor()
r_first_neuron_hm = [(k, visualFieldMagnitude(direction[:,:,k],magnitude[:,:,k])) for k in keys]
sections = hv.HoloMap(r_first_neuron_hm, kdims=dimensions)
sections
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
<ipython-input-14-c117964c8a5e> in <module>()
     13 keys = [i for i in range(timesteps)]
     14 oneColor()
---> 15 r_first_neuron_hm = [(k, visualFieldMagnitude(direction[:,:,k],magnitude[:,:,k])) for k in keys]
     16 sections = hv.HoloMap(r_first_neuron_hm, kdims=dimensions)
     17 sections

/afs/inf.ed.ac.uk/user/s12/s1247380/Documents/HonoursProject/Python/dynamics.py in visualFieldMagnitude(orientations, magnitude, aspect, fix_scale)
    237                     bars = plotbar(i,j,orientations[i,j], l=0.9, width=magnitude[i,j]*3)
    238                 else:
--> 239                     bars *= plotbar(i, j, orientations[i,j], l=0.9, width=magnitude[i,j]*3)
    240     #renderer.save(bars, 'orientations')
    241 

/afs/inf.ed.ac.uk/user/s12/s1247380/Documents/HonoursProject/Python/venv/lib/python2.7/site-packages/holoviews/core/overlay.pyc in __mul__(self, other)
    140             raise NotImplementedError
    141 
--> 142         return Overlay(items=self.relabel_item_paths(items)).display('all')
    143 
    144 

/afs/inf.ed.ac.uk/user/s12/s1247380/Documents/HonoursProject/Python/venv/lib/python2.7/site-packages/holoviews/core/layout.pyc in relabel_item_paths(cls, items)
    362         count = 2
    363         for path, item in items:
--> 364             new_path, count = cls.new_path(path, item, paths, count)
    365             new_path = tuple(''.join((p[0].upper(), p[1:])) for p in new_path)
    366             path_items.append(item)

/afs/inf.ed.ac.uk/user/s12/s1247380/Documents/HonoursProject/Python/venv/lib/python2.7/site-packages/holoviews/core/layout.pyc in new_path(cls, path, item, paths, count)
    336         path = tuple(fn(p) for (p, fn) in zip(path, sanitizers))
    337         while any(path[:i] in paths or path in [p[:i] for p in paths]
--> 338                   for i in range(1,len(path)+1)):
    339             path = path[:2]
    340             pl = len(path)

/afs/inf.ed.ac.uk/user/s12/s1247380/Documents/HonoursProject/Python/venv/lib/python2.7/site-packages/holoviews/core/layout.pyc in <genexpr>((i,))
    336         path = tuple(fn(p) for (p, fn) in zip(path, sanitizers))
    337         while any(path[:i] in paths or path in [p[:i] for p in paths]
--> 338                   for i in range(1,len(path)+1)):
    339             path = path[:2]
    340             pl = len(path)

KeyboardInterrupt: 
In [10]:
t = np.arange(0,timesteps,1)

plotOneField((1,0),t,nosn,rs)
Out[10]:
In [8]:
%%output size=300
m = 10
n = 10
tau = 6
# Number of orientation selective neurons
nosn = 9
timesteps = 100
# for vonMises function
k = 0.25
A = 3
# for the weight matrix
distance_scaling = 0.00005
orientation_scaling = 0.00005
# Set the number of colors for plotting, based on the number of orientation selective neurons
setNumberOfColors(nosn)

orientations = np.arange(0, np.pi, np.pi/nosn)
#ac_orient = np.random.rand(m,n)
responses = np.zeros((nosn, timesteps))
t = np.arange(0,timesteps,1)

spikes_ = vonMises(A,k,ac_orient,orientations)
spikes = spikes_.ravel()
r = np.zeros(len(spikes))
drdt = spikes/tau
rs = np.zeros(spikes.shape + (len(t),))

for s in range(len(t)):
    r = r + drdt
    drdt = (-r + spikes)/tau + np.dot(matrix2,r)
    rs[:,s] = r

#r_first_neuron = rs[:,1,1,:]
rs = np.reshape(rs, spikes_.shape + (len(t),))
(direction, magnitude) = populationVector(orientations, rs, nosn, timesteps)
dimensions = ['T']
keys = [i for i in range(timesteps)]
oneColor()
r_first_neuron_hm = [(k, visualFieldMagnitude(direction[:,:,k],magnitude[:,:,k])) for k in keys]
sections = hv.HoloMap(r_first_neuron_hm, kdims=dimensions)
sections
Out[8]: